<?php

namespace app\admin\model\rexam;

use think\Model;


class Rexam extends Model
{

    

    

    // 表名
    protected $name = 'rexam';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'examdata_text',
        'areadata_text',
        'limitdata_text',
        'randomdata_text',
        'pointsdata_text',
        'groupdata_text',
        'binddata_text',
        'anadata_text',
        'starttime_text',
        'expiretime_text',
        'status_text'
    ];


    public function user()
    {
        return $this->belongsTo('User', 'rexam_bind_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    
    public function getExamdataList()
    {
        return ['0' => __('Examdata 0'), '1' => __('Examdata 1')];
    }

    public function getAreadataList()
    {
        return ['0' => __('Areadata 0'), '1' => __('Areadata 1'), '2' => __('Areadata 2')];
    }

    public function getLimitdataList()
    {
        return ['0' => __('Limitdata 0'), '1' => __('Limitdata 1')];
    }

    public function getRandomdataList()
    {
        return ['0' => __('Randomdata 0'), '1' => __('Randomdata 1')];
    }

    public function getPointsdataList()
    {
        return ['0' => __('Pointsdata 0'), '1' => __('Pointsdata 1')];
    }

    public function getGroupdataList()
    {
        return ['0' => __('Groupdata 0'), '1' => __('Groupdata 1')];
    }

    public function getBinddataList()
    {
        return ['0' => __('Binddata 0'), '1' => __('Binddata 1')];
    }

    public function getAnadataList()
    {
        return ['0' => __('Anadata 0'), '1' => __('Anadata 1')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getExamdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['examdata']) ? $data['examdata'] : '');
        $list = $this->getExamdataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAreadataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['areadata']) ? $data['areadata'] : '');
        $list = $this->getAreadataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLimitdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['limitdata']) ? $data['limitdata'] : '');
        $list = $this->getLimitdataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRandomdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['randomdata']) ? $data['randomdata'] : '');
        $list = $this->getRandomdataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPointsdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pointsdata']) ? $data['pointsdata'] : '');
        $list = $this->getPointsdataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGroupdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['groupdata']) ? $data['groupdata'] : '');
        $list = $this->getGroupdataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBinddataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['binddata']) ? $data['binddata'] : '');
        $list = $this->getBinddataList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getAnadataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['anadata']) ? $data['anadata'] : '');
        $list = $this->getAnadataList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getExpiretimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expiretime']) ? $data['expiretime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setStarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setExpiretimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
